<template>
  <el-dialog
    v-el-drag-dialog
    title="客户等级调整"
    :visible.sync="dialogVisible"
    width="30%"
    @close="reset"
  >
    <el-form ref="dataForm" class="form" :model="query" label-position="right" label-width="80px">
      <el-form-item v-if="list.length<2" label="当前等级" class="merge-item">
        <el-input v-model="query.Level" style="width: 170px; margin-right: 2px;" disabled />
      </el-form-item>
      <el-form-item label="调整等级" class="merge-item">
        <el-select v-model="query.unCheckQuality" placeholder="请选择" style="width: 170px; margin-right: 2px;">
          <!-- <el-option label="请选择" value="-1" /> -->
          <el-option v-for="(l,i) in cmsLevleList" :key="i" :label="l.levelName" :value="l.levelNum" />
        </el-select>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="success">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import { customerLevelEquityList, queryCustomerLevelUpdate } from '@/api'
  export default {
    name: 'edit',
    props: ['cmsLevelEnum', 'fetchData'],
    data() {
      return {
        dialogVisible: false,
        query: {
          Level: ''
        },
        list: [],
        cmsLevleList: []
      }
    },
    created() {
      this.getcmsLevle()
    },
    methods: {
      open(list) {
        this.list = list
        if (this.cmsLevelEnum.find(l => list[0].csmQuality === l.levelNum)) {
          this.query.Level = this.cmsLevelEnum.find(l => list[0].csmQuality === l.levelNum).levelName
        }
        console.log(list)
        this.dialogVisible = true
      },
      async success() {
        const params = {
          unCheckQuality: this.query.unCheckQuality,
          csmCodes: this.list.map(l => l.csmCode).join(',')
        }
        try {
          const res = await queryCustomerLevelUpdate(params)
          if (res.success) {
            this.$message.success('修改成功')
            console.log(this.fetchData)
            this.fetchData({})
            this.dialogVisible = false
          }
        } catch (e) {
          console.log(e)
        }
      },
      reset() {

      },
      async getcmsLevle() {
        try {
          const res = await customerLevelEquityList({ 'keyStatus': 2, currentPage: 1, pageSize: 20 })
          this.cmsLevleList = res.data.rows
        } catch (e) {
          console.log(e)
        }
      }
    }
  }
</script>
